<template>
    <div>
        <iview-table
                ref="table"
                :span1="19"
                :span2="5"
                :baseURL="queryModel.baseURL"
                :menuId="dataModel.menuId"
                :columns="dataModel.columns"
                :order="dataModel.order"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :defaultFilters="queryModel.defaultFilters"
                v-on="{changeTotalSize:changeTotalSize,changeSelect:changeSelect,events:events}">
        </iview-table>
        <br>
        <iview-page
                style="margin-bottom: 200px"
                :totalSize="pageModel.totalSize"
                :pageNumber="pageModel.pageNumber"
                :pageSize="pageModel.pageSize"
                :pageSizeOpts="pageModel.pageSizeOpts"
                v-on="{changePageNumber:changePageNumber,changePageSize:changePageSize}">
        </iview-page>
    </div>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        data () {
            return {
                baseURL: '/user/skin/type',
                showAdd: false,
                selectRows: [],
                formItem: {
                    id: '',
                    patientId: '',
                    complaintId: '',
                    supplementContent: '',
                    experimenter: '',
                    doctor: ''
                },
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/skin/type',
                    defaultFilters: [
                        {'field': 'patient_id', 'value1': -1, 'operate': '=='}
                    ]
                },
                dataModel: {
                    menuId: 0,
                    columns: [
                        {
                            type: 'selection',
                            width: 60,
                            align: 'center'
                        },
                        {
                            title: '调查时间',
                            key: 'creationTime',
                            render: (h, params) => {
                                return h('span', this.$moment(params.row.creationTime).format('YYYY年MM月DD日'))
                            }
                        },
                        {
                            title: '皮肤分类结果',
                            render: (h, params) => {
                                let temp = ''
                                if (params.row.type1 === 1) {
                                    temp += '油性'
                                } else if (params.row.type1 === 2) {
                                    temp += '干性'
                                }
                                temp +=  ','
                                if (params.row.type2 === 1) {
                                    temp += '敏感'
                                } else if (params.row.type2 === 2) {
                                    temp += '耐受'
                                }
                                temp +=  ','
                                if (params.row.type3 === 1) {
                                    temp += '色素'
                                } else if (params.row.type3 === 2) {
                                    temp += '非色素'
                                }
                                temp +=  ','
                                if (params.row.type4 === 1) {
                                    temp += '皱纹'
                                } else if (params.row.type4 === 2) {
                                    temp += '紧致'
                                }
                                return h('span', temp)
                            }
                        },
                        {
                            title: '角标',
                            render: (h, params) => {
                                let temp = ''
                                if (params.row.type1 === 1) {
                                    temp += 'O'
                                    temp += params.row.sub1 + ','
                                } else if (params.row.type1 === 2) {
                                    temp += 'D'
                                    temp += params.row.sub1 + ','
                                }
                                if (params.row.type2 === 1) {
                                    temp += 'S'
                                    temp += params.row.sub2 + ','
                                } else if (params.row.type2 === 2) {
                                    temp += 'R'
                                    temp += params.row.sub2 + ','
                                }
                                if (params.row.type3 === 1) {
                                    temp += 'P'
                                    temp += params.row.sub3 + ','
                                } else if (params.row.type3 === 2) {
                                    temp += 'N'
                                    temp += params.row.sub3 + ','
                                }
                                if (params.row.type4 === 1) {
                                    temp += 'W'
                                    temp += params.row.sub4
                                } else if (params.row.type4 === 2) {
                                    temp += 'T'
                                    temp += params.row.sub4
                                }
                                return h('span', temp)
                            }
                        },
                        {
                            title: '操作',
                            width: 200,
                            align: 'center',
                            render: (h, params) => {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'info',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.recommend(params.row)
                                            }
                                        }
                                    }, '推荐')
                                ]);
                            }
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [10, 50, 100, 500]
                }
            };
        },
        methods: {
            events (item) {
                let path = item.path
            },
            recommend (row) {
                this.$emit('recommend', row)
            },
            refresh () {
                this.queryModel.defaultFilters.length = 0
                if (this.$store.state.app.patientId) {
                    this.queryModel.defaultFilters.push({'field': 'patient_id', 'value1': this.$store.state.app.patientId, 'operate': '=='})
                }
                this.$refs.table.refresh()
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            init () {
                this.refresh()
            }
        },
        mounted () {
        }
    }
</script>

<style>

</style>
